import $axios from "@/assets/js/http.js";
import qs from 'qs';
import axios from "axios";
import wx from 'weixin-js-sdk';

export default {
  getUserInfo: function (data) {
    return new Promise((resolve, reject) => {
      var jkcsUserInfo = sessionStorage.getItem("jkcsUserInfo");
      if (jkcsUserInfo) {
        resolve(jkcsUserInfo);
      } else {
        $axios.http.post({
          funcName: "/gzd/getUserInfo.service",
        }).then(res => {
          sessionStorage.setItem("jkcsUserInfo", JSON.stringify(res.data));
          resolve(JSON.stringify(res.data))
        }).catch(err => {
          reject(err)
        })
      }
    })
  },
  // 获取默认就诊人
  getDefaultInfo: function (data) {
    return new Promise((resolve, reject) => {
      var getDefaultInfo = sessionStorage.getItem("getDefaultInfo");
      if (getDefaultInfo && getDefaultInfo != 'null') {
        resolve(getDefaultInfo);
      } else {
        $axios.http.post({
          funcName: "/gzd/yygh/getJzrInfo.service",
        }).then(res => {
          sessionStorage.setItem("getDefaultInfo", JSON.stringify(res.data));
          resolve(JSON.stringify(res.data))
        }).catch(err => {
          reject(err)
        })
      }
    })
  },
  // 获取最新该医院的就诊记录 获取就诊人信息 暂时不用
  getNewestInfo: function (dara) {
    let hosInfo = sessionStorage.getItem('hosInfo');
    hosInfo = JSON.parse(hosInfo ? hosInfo : '');
    return new Promise((resolve, reject) => {
      $axios.http.post({
        funcName: "/gzd/yygh/getOrderRecords.service",
        params: {
          hosOrgCode: hosInfo['hosCode']
        }
      }).then(res => {
        let data = '{}';
        if (res.data && res.data['orders'] && res.data['orders'].length > 0) {
          data = res.data['orders'][0];
        }
        sessionStorage.setItem("getNewestInfo", JSON.stringify(data));
        resolve(JSON.stringify(data))
      }).catch(err => {
        reject(err)
      })
    })
  },
  getLogin(data) {
    return new Promise((resolve, reject) => {
      let type = {
        headers: {
          'Content-Type': 'application/json;charset=UTF-8'
        }
      }
      axios.post(data.funcName, JSON.stringify(data.params), type).then(function (result) {
        var code = result.data["code"];
        resolve(result)

      }).catch(err => {
        reject(err)
      })


    })




  },
  getSignature(config) {
    // 微信获取签名
    return new Promise((resolve, reject) => {
      let url = window.location.href;
      url = url.split("#")[0];
      $axios.http.post({
        funcName: "/gzd/wechat/getSignature.service",
        params: {
          url: url
        }
      }).then(res => {
        let data = res.data;
        wx.config({
          appId: data.appid, // 必填，公众号的唯一标识
          timestamp: data.timestamp, // 必填，生成签名的时间戳
          nonceStr: data.noncestr, // 必填，生成签名的随机串
          signature: data.signature, // 必填，签名，见附录1
          jsApiList: config['jsApiList'] // 必填，openLocation
        });
        wx.ready(function (res) {
          resolve(res);
        })
        wx.error(function (res) {
          this.$public.toast(res['errMsg']);
          resolve(res);
        });

      }).catch(err => {
        reject(err)
      })
    })
  }


}